package com.tm.dk.controller;


import com.tm.dk.service.UserService;
import com.tm.entity.SysUserEntity;
import com.tm.exception.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    //登陆
    @RequestMapping("login")
    public Result login(String username, String password){
        //验参
        if(StringUtils.isEmpty(username)){
            return Result.error(400,"缺少参数");
        }
        if(StringUtils.isEmpty(password)){
            return Result.error(400,"缺少参数");
        }
        //校验密码
        return Result.success(userService.login(username,password));
    }

    //登出
    @PostMapping("logout")
    public Result logout(HttpServletRequest request){
        request.getSession().removeAttribute("user");
        return Result.success();
    }



}

